package com.lanou.horo.zhuizhui.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView.ScaleType;
import android.widget.Toast;


import com.android.volley.toolbox.ImageLoader;
import com.lanou.horo.zhuizhui.R;
import com.lanou.horo.zhuizhui.utility.customImage.ImageControl;
import com.lanou.horo.zhuizhui.utility.imageLoader.VolleySingleton;
import com.lanou.horo.zhuizhui.utility.customImage.SmoothImageView;


public class SpaceImageDetailActivity extends Activity {
    private ImageLoader imageLoader;
    private ArrayList<String> mDatas;
    private int mPosition;
    private int mLocationX;
    private int mLocationY;
    private int mWidth;
    private int mHeight;
    SmoothImageView imageView = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        imageLoader = VolleySingleton.getInstance().getImageLoader();
        mDatas = (ArrayList<String>) getIntent().getSerializableExtra("images");
        mPosition = getIntent().getIntExtra("position", 0);
        mLocationX = getIntent().getIntExtra("locationX", 0);
        mLocationY = getIntent().getIntExtra("locationY", 0);
        mWidth = getIntent().getIntExtra("width", 0);
        mHeight = getIntent().getIntExtra("height", 0);

        imageView = new SmoothImageView(this);


        imageView.setOriginalInfo(mWidth, mHeight, mLocationX, mLocationY);
        imageView.transformIn();
        imageView.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
        imageView.setScaleType(ScaleType.FIT_CENTER);
        setContentView(imageView);
        imageView.setImageUrl(mDatas.get(mPosition), imageLoader);





//		ImageLoader.getInstance().displayImage(mDatas.get(mPosition), imageView);
//		imageView.setImageResource(R.mipmap.saberjiang);
//		 ScaleAnimation scaleAnimation = new ScaleAnimation(mWidth, 1f, mHeight,
//		 1.0f, /*Animation.RELATIVE_TO_SELF*/mLocationX, 1f, /*Animation.RELATIVE_TO_SELF*/mLocationY,
//		 1f);
//		 scaleAnimation.setDuration(1000);
//		 scaleAnimation.setInterpolator(new AccelerateInterpolator());
//		 imageView.startAnimation(scaleAnimation);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
//    public void onWindowFocusChanged(boolean hasFocus) {
//        super.onWindowFocusChanged(hasFocus);
//        init();
//    }
    @Override
    public void onBackPressed() {
        imageView.setOnTransformListener(new SmoothImageView.TransformListener() {
            @Override
            public void onTransformComplete(int mode) {
                if (mode == 2) {
                    finish();
                }
            }
        });
        imageView.transformOut();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (isFinishing()) {
            overridePendingTransition(0, 0);
        }
    }

//    private void init() {
////        tvTitle.setText("图片测试");
////        // 这里可以为imgcontrol的图片路径动态赋值
////        // ............
//
//        Bitmap bmp;
//        if (imageView.getDrawingCache() != null) {
//            bmp = Bitmap.createBitmap(imageView.getDrawingCache());
//        } else {
//            bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
//        }
//        Rect frame = new Rect();
////        getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
////        int statusBarHeight = frame.top;
////        int screenW = this.getWindowManager().getDefaultDisplay().getWidth();
////        int screenH = this.getWindowManager().getDefaultDisplay().getHeight()
////                - statusBarHeight;
////        if (bmp != null) {
////            imageView.imageInit(bmp, screenW, screenH, statusBarHeight,
////                    new ImageControl.ICustomMethod() {
////
////                        @Override
////                        public void customMethod(Boolean currentStatus) {
////                            // 当图片处于放大或缩小状态时，控制标题是否显示
////                            if (currentStatus) {
//////                                llTitle.setVisibility(View.GONE);
////                            } else {
//////                                llTitle.setVisibility(View.VISIBLE);
////                            }
////                        }
////                    });
////        }
////        else
////        {
////            Toast.makeText(this, "图片加载失败，请稍候再试！", Toast.LENGTH_SHORT)
////                    .show();
////        }
//    }
//    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        switch (event.getAction() & MotionEvent.ACTION_MASK) {
//            case MotionEvent.ACTION_DOWN:
//                imageView.mouseDown(event);
//                break;
//            /**
//             * 非第一个点按下
//             */
//            case MotionEvent.ACTION_POINTER_DOWN:
//
//                imageView.mousePointDown(event);
//
//                break;
//            case MotionEvent.ACTION_MOVE:
//                imageView.mouseMove(event);
//
//                break;
//
//            case MotionEvent.ACTION_UP:
//                imageView.mouseUp();
//                break;
//
//        }
//
//        return super.onTouchEvent(event);
//    }
}
